import { createRouter, createWebHashHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';
import localCache from '@/utils/localCache';
import { firstMenu } from '@/utils/mapMenus';
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/main'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('../views/main/main.vue'),
    children: []
  },
  {
    path: '/:pathMatch(.*)',
    component: () => import('../views/notFound/notFound.vue')
  }
];
const router = createRouter({
  routes,
  history: createWebHashHistory()
});
router.beforeEach((to, from) => {
  if (to.path === '/main') {
    if (localCache.getCache('token')) {
      return firstMenu.url;
    } else {
      return '/login';
    }
  }
});
export default router;
